package com.car.intercept;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONArray;

import org.apache.log4j.Logger;

import com.car.action.admin.LoginController;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;

public class AdminInterceptor implements Interceptor {

	private static Logger logger = Logger.getLogger(AdminInterceptor.class);
	
    public void intercept(Invocation inv) {
        Controller controller = inv.getController();
//        HttpServletRequest request = controller.getRequest();
        if (controller.getSessionAttr(LoginController.ADMIN_SESSION_KEY) == null) {
        	String message = "请先登录再进行操作！";
            controller.setAttr("message", message);
            controller.render("/WEB-INF/view/login/index.html");
        } else {
        	controller.setSessionAttr(LoginController.ADMIN_SESSION_KEY, controller.getSessionAttr(LoginController.ADMIN_SESSION_KEY));
        	controller.setAttr(LoginController.ADMIN_SESSION_KEY, controller.getSessionAttr(LoginController.ADMIN_SESSION_KEY));
            inv.invoke();
        }
        
    }

}
